package nz.ac.massey.cs.se400_2013.ass3.plugin;

import javax.swing.JPanel;

import nz.ac.massey.cs.se400_2013.ass3.EditorPlugin;
import nz.ac.massey.cs.se400_2013.ass3.Student;

public class StudentEditor implements EditorPlugin{

	private StudentEditorUi editor;
	private Object object;
	public StudentEditor(){
		this.editor = new StudentEditorUi();
	}
	public JPanel getEditor() {
		return this.editor;
	}

	public void edit(Object obj) {
		this.object = obj;
		this.editor.setName(((Student)obj).getName());
		this.editor.setFirstName(((Student)obj).getFirstName());
	}

	@Override
	public boolean canEditInstanceOf(Class type) {
		if(type == Student.class){
			return true;
		}
		return false;
	}
	@Override
	public void saveObject() {
		((Student)this.object).setName(this.editor.getName());
		((Student)this.object).setFirstName(this.editor.getFirstName());
	}
	@Override
	public void addChangeListener(ChangeListener listener) {
		this.addChangeListener(listener);
	}
}


